package com.limh.readers.net

import com.limh.readers.comm.Comm
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

/**
 * Function:
 * author: limh
 * time:2017/7/21
 */
class BaseRetrofit {
    private var retrofit: Retrofit

    fun <S> createService(sClass: Class<S>): S {
        return retrofit.create(sClass)
    }

    init {
        val httpClient: OkHttpClient.Builder = OkHttpClient.Builder()
        val builder: Retrofit.Builder = Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(Comm.BASE_URL)
        retrofit = builder.client(httpClient.build()).build()
    }
}